<?php
/**
 * @copyright  For copyright and license information, read the COPYING.txt file.
 * @link       /COPYING.txt
 * @license    Academic Free License (AFL 3.0)
 * @package     default_default
 */

/**
 * Install database configuration template
 *
 * @see Mage_Install_Block_Config
 * @var Mage_Install_Block_Config $this
 */
?>
<script type="text/javascript">
//<![CDATA[
var dbTypeIds = [];
function showContent(select)
{
    dbTypeIds.each(function (name) {
        $(name + '_conn_form').hide()
    });
    $(select.value + '_conn_form').show();
}
//]]>
</script>

<fieldset class="group-select">
 <legend><?php echo $this->__('Connection') ?></legend>
    <h4 class="legend"><?php echo $this->__('Database Connection') ?></h4>
    <ul>
        <?php $dbTypeOptions = $this->getDatabaseBlocks(); ?>
        <?php if (count($dbTypeOptions) > 0): ?>
        <li>
            <div class="input-box">
                <label for="prefix"><?php echo $this->__('Database Type') ?></label><br />
                <select name="config[db_model]" onchange="showContent(this)">
                    <?php foreach($dbTypeOptions as $block): ?>
                        <option value="<?php echo $block->getIdPrefix()?>" <?php if($this->getFormData()->getDbModel() == $block->getIdPrefix()):?>selected="selected"<?php endif ?>><?php echo $block->getTitle()?></option>
                    <?php endforeach ?>
                </select>
            </div>
        </li>
        <?php endif ?>

        <?php foreach ($dbTypeOptions as $block): ?>
            <script type="text/javascript">
            //<![CDATA[
                dbTypeIds[dbTypeIds.length] = "<?php echo $block->getIdPrefix(); ?>";
            //]]>
            </script>
            <?php $block = $this->getDatabaseBlock($block->getIdPrefix()) ?>

            <div id="<?php echo $block->getIdPrefix() ?>_conn_form" <?php if($this->getFormData()->getDbModel() != $block->getIdPrefix()):?>style="display:none;"<?php endif ?>>
                <ul>
                    <?php echo $block->toHtml(); ?>
                </ul>
            </div>
        <?php endforeach ?>
    </ul>
</fieldset>
